﻿using System;
using System.Data;

namespace datatable_tutorial
{
    class Program
    {
        static void Main(string[] args)
        {

            DataTable dataTable = new DataTable();

            DataColumn col1 = new DataColumn("Id", typeof(int));
            col1.AutoIncrement = true;

            DataColumn col2 = new DataColumn("Name", typeof(string));
            DataColumn col3 = new DataColumn("TimeStamp", typeof(DateTime));
            dataTable.Columns.AddRange(new DataColumn[] { col1, col2, col3 });

            dataTable.Rows.Add(null, "John", DateTime.Now);
            dataTable.Rows.Add(null, "Jane", DateTime.Now);

            // Output columns names to the console
            Console.WriteLine("DataTable has {0} DataColumns named:",
                dataTable.Columns.Count);
            foreach (DataColumn col in dataTable.Columns)
                Console.WriteLine("\t{0}", col.ColumnName);
            Console.WriteLine("\nPress any key to continue.");
            Console.ReadKey();

            // Output rows to the console
            Console.WriteLine("DataTable has {0} rows: ",
                dataTable.Rows.Count);

            foreach (DataRow dataRow in dataTable.Rows)
            {

                foreach (DataColumn dataColumn in dataTable.Columns)
                {
                    Console.WriteLine(dataRow[dataColumn].ToString());
                }
                Console.ReadKey();
            }
        }
    }
}
